//
//  YPGuidePageCollectionViewController.m
//  Youpin
//
//  Created by xiaowuxiaowu on 2017/9/2.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "YPGuidePageCollectionViewController.h"
#import "BaseCCell.h"
#import "ViewController.h"
@interface YPGuidePageCollectionViewController ()
@property (nonatomic,copy)NSArray *imgs;
@property (nonatomic,strong)UIPageControl *pageControl;

@property (nonatomic,strong)UIButton *actionButton;
@end

@implementation YPGuidePageCollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (instancetype)init
{
    // 创建一个流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    // 设置cell的尺寸
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    // 设置滚动的方向
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    // 行间距
    layout.minimumLineSpacing = 0;
    
    // 设置cell之间的间距
    layout.minimumInteritemSpacing = 0;
    
    return [super initWithCollectionViewLayout:layout];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.imgs = @[@"Guidepage1",@"Guidepage2",@"Guidepage3"];
    [self.collectionView registerClass:[BaseCCell class] forCellWithReuseIdentifier:reuseIdentifier];
    self.view.backgroundColor = self.collectionView.backgroundColor = [UIColor whiteColor];
    //    self.collectionView.bounces = NO;
    
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    self.collectionView.pagingEnabled = YES;
    
//    self.pageControl = [[UIPageControl alloc]init];
//    self.pageControl.numberOfPages = self.imgs.count;
//    self.pageControl.currentPageIndicatorTintColor = TP_COLOR_245;
//    self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
//    [self.view addSubview:self.pageControl];
//    [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_equalTo(-20.0);
//        make.centerX.mas_equalTo(self.view);
//        make.height.mas_equalTo(20.0);
//    }];
    [self.collectionView reloadData];
    
    
//    _actionButton = [UIButton buttonWithFrame:CGRectZero title:@"" font:fontSystemOfSize(15) color:TPBlack_666666];
//    [self.view addSubview:_actionButton];
//    _actionButton.userInteractionEnabled = YES;
//    [self.view bringSubviewToFront:_actionButton];
//    [_actionButton setBackgroundImageColor:[UIColor clearColor] forState:UIControlStateNormal];
//    _actionButton.alpha = 0.0;
//    [_actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_equalTo(0);
//        make.centerX.mas_equalTo(self.view);
//        make.height.mas_equalTo(self.view.mas_height).multipliedBy(0.4);
//        make.width.mas_equalTo(self.view);
//    }];
//
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.imgs.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BaseCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.indexPath = indexPath;
    cell.image_view.frame = cell.bounds;
    cell.image_view.image = ImageNamed(self.imgs[indexPath.row]);
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 2){
        [XWCommon shareAppDelegate].window.rootViewController = [ViewController new];
    }
}
#pragma mark <UICollectionViewDelegate>

//-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
//    self.pageControl.currentPage = indexPath.row;
//}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat page = scrollView.contentOffset.x / scrollView.width;
    self.pageControl.currentPage =  page;
    self.actionButton.alpha = round(page) == 2;
}

/*
 // Uncomment this method to specify if the specified item should be highlighted during tracking
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 // Uncomment this method to specify if the specified item should be selected
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
 return NO;
 }
 
 - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
 return NO;
 }
 
 - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
 
 }
 */

@end

